import { getToken, setToken, removeToken } from '@/utils/auth'
import permission from './permission';

const user = {
  state: {
    user: '',
    token: getToken()
  },

  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    }
  },

  actions: {
    // 用户名登录
    LoginByUsername({ commit }, user) {
      console.log('user', user)
      commit('SET_TOKEN', user)
      setToken(user)
    },

    // 登出
    LogOut({ commit }) {
      return new Promise((resolve) => {
        commit('SET_TOKEN', '')
        sessionStorage.clear()
        location.reload()
        removeToken()
        resolve()
      })
    }
  }
}

export default user
